package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Sceneryarea;
import com.ruoyi.system.service.ISceneryareaService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 景区Controller
 * 
 * @author ruoyi
 * @date 2020-10-15
 */
@Controller
@RequestMapping("/system/sceneryarea")
public class SceneryareaController extends BaseController
{
    private String prefix = "system/sceneryarea";

    @Autowired
    private ISceneryareaService sceneryareaService;

    @RequiresPermissions("system:sceneryarea:view")
    @GetMapping()
    public String sceneryarea()
    {
        return prefix + "/sceneryarea";
    }

    /**
     * 查询景区列表
     */
    @RequiresPermissions("system:sceneryarea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sceneryarea sceneryarea)
    {
        startPage();
        List<Sceneryarea> list = sceneryareaService.selectSceneryareaList(sceneryarea);
        return getDataTable(list);
    }

    /**
     * 导出景区列表
     */
    @RequiresPermissions("system:sceneryarea:export")
    @Log(title = "景区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sceneryarea sceneryarea)
    {
        List<Sceneryarea> list = sceneryareaService.selectSceneryareaList(sceneryarea);
        ExcelUtil<Sceneryarea> util = new ExcelUtil<Sceneryarea>(Sceneryarea.class);
        return util.exportExcel(list, "sceneryarea");
    }

    /**
     * 新增景区
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存景区
     */
    @RequiresPermissions("system:sceneryarea:add")
    @Log(title = "景区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sceneryarea sceneryarea)
    {
        return toAjax(sceneryareaService.insertSceneryarea(sceneryarea));
    }

    /**
     * 修改景区
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Sceneryarea sceneryarea = sceneryareaService.selectSceneryareaById(id);
        mmap.put("sceneryarea", sceneryarea);
        return prefix + "/edit";
    }

    /**
     * 修改保存景区
     */
    @RequiresPermissions("system:sceneryarea:edit")
    @Log(title = "景区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sceneryarea sceneryarea)
    {
        return toAjax(sceneryareaService.updateSceneryarea(sceneryarea));
    }

    /**
     * 删除景区
     */
    @RequiresPermissions("system:sceneryarea:remove")
    @Log(title = "景区", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sceneryareaService.deleteSceneryareaByIds(ids));
    }
}
